<?php
require_once '../config/config.php';
require_once 'inc/session.php';

$menu = 32;

if (isset($_POST['submit'])) {
    foreach ($_POST as $key => $value) {
        if ($key != 'submit') {
            $sql = "UPDATE abonnement SET prix = " . $value . " WHERE id = " . $key;
            mysql_query($sql) or die(mysql_error());
        }
    }
    $message_succes = 'Mise à jour effectuée avec succès.';
}

$sql_taux_tva = "SELECT value FROM taux_tva WHERE id = 1";
$req_taux_tva = mysql_query($sql_taux_tva) or die(mysql_error());
$res_taux_tva = mysql_fetch_array($req_taux_tva);

$taux_tva = $res_taux_tva['value'];

$sql = 'SELECT id, label, prix FROM abonnement';
$req = mysql_query($sql) or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Interface Administration | L'essentiel du sup</title>
        <link rel="shortcut icon" href="images/favicon.ico" />
        <link rel="stylesheet" href="css/style.css" type="text/css" />
        <link rel="stylesheet" href="css/plugins/jquery.wysiwyg.css" type="text/css" />
        <!--[if IE 9]>
            <link rel="stylesheet" media="screen" href="css/ie9.css"/>
        <![endif]-->
        <!--[if IE 8]>
            <link rel="stylesheet" media="screen" href="css/ie8.css"/>
        <![endif]-->
        <!--[if IE 7]>
            <link rel="stylesheet" media="screen" href="css/ie7.css"/>
        <![endif]-->
        <style>
            .stdtable {
                text-align: center;
            }
            input[type='text'] {
                width: 50px;
            }
        </style>
        <script type="text/javascript" src="js/plugins/jquery-1.7.min.js"></script>
        <script type="text/javascript" src="js/plugins/jquery.flot.min.js"></script>
        <script type="text/javascript" src="js/plugins/jquery.flot.resize.min.js"></script>
        <script type="text/javascript" src="js/plugins/jquery-ui-1.8.16.custom.min.js"></script>
        <script type="text/javascript" src="js/custom/general.js"></script>
        <script type="text/javascript" src="js/plugins/wysiwyg/jquery.wysiwyg.js"></script>
        <script type="text/javascript" src="js/plugins/wysiwyg/wysiwyg.image.js"></script>
        <script type="text/javascript" src="js/plugins/wysiwyg/wysiwyg.link.js"></script>
        <script type="text/javascript" src="js/plugins/wysiwyg/wysiwyg.table.js"></script>
        <script type="text/javascript" src="js/plugins/wysiwyg/wysiwyg.i18n.js"></script>
        <script type="text/javascript" src="js/plugins/wysiwyg/i18n/lang.fr.js"></script>
        <script type="text/javascript">
            jQuery(document).ready(function() {
                jQuery('.input-prix').keyup(function() {
                    id = jQuery(this).attr('id');
                    prix = jQuery(this).val();
                    prix_tva = (prix / (1 + <?php echo $taux_tva ?>)).toFixed(2);
                    jQuery('#tva_' + id).text(prix_tva);
                });
            });
        </script>
        <!--[if lt IE 9]>
                <script src="js/css3-mediaqueries.js"></script>
        <![endif]-->
    </head>
    <body class="loggedin">
        <?php include('inc/header.php') ?>
        <div class="mainwrapper">
            <div class="mainwrapperinner">
                <?php include('inc/menu.php') ?>
                <div class="maincontent noright">
                    <div class="maincontentinner">
                        <ul class="maintabmenu">
                            <li class="current">
                                <a>Gestion de l’offre</a>
                            </li>
                        </ul>
                        <div class="content">
                            <?php if (!empty($message_succes)) {
                                ?>
                                <div class="notification msgsuccess">
                                    <a class="close"></a>
                                    <p><?php echo $message_succes; ?></p>
                                </div>
                            <?php } ?>
                            <?php if (!empty($message_erreur)) {
                                ?>
                                <div class="notification msgerror">
                                    <a class="close"></a>
                                    <p><?php echo $message_erreur ?></p>
                                </div>
                            <?php } ?>
                            <form id="validate" class="stdform stdform2" action="" method="post">
                                <div class="contenttitle radiusbottom0">
                                    <h2 class="table"><span>Prix des abonnements</span></h2>
                                </div>	
                                <table cellpadding="0" cellspacing="0" border="0" class="stdtable">
                                    <colgroup>
                                        <col class="con0" />
                                        <col class="con1" />
                                        <col class="con0" />
                                    </colgroup>
                                    <thead>
                                        <tr>
                                            <th class="head0">Nombre de bénéficiaires par institution</th>
                                            <th class="head1">Prix annuel de l’abonnement TTC</th>
                                            <th class="head0">Prix annuel de l’abonnement HT</th>
                                        </tr>
                                    </thead>
                                    <tfoot>
                                        <tr>
                                            <th class="head0">Nombre de bénéficiaires par institution</th>
                                            <th class="head1">Prix annuel de l’abonnement TTC</th>
                                            <th class="head0">Prix annuel de l’abonnement HT</th>
                                        </tr>
                                    </tfoot>
                                    <tbody>
                                        <?php while ($res = mysql_fetch_array($req)) { ?>
                                            <tr>
                                                <td>
                                                    <?php echo $res['label'] ?>
                                                </td>
                                                <td>
                                                    <input type="text" name="<?php echo $res['id'] ?>" class="input-prix" id="<?php echo $res['id'] ?>" value="<?php echo $res['prix'] ?>" />
                                                    <span style="margin-left: 5px;">€</span>
                                                </td>
                                                <td><span id="tva_<?php echo $res['id'] ?>"><?php echo sprintf("%.2f", ($res['prix'] / (1 + $taux_tva))) ?></span> €</td>
                                            </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                                <p class="stdformbutton">
                                    <button name="submit" class="submit radius2">Enregistrer</button>
                                    <input type="reset" class="reset radius2" value="Annuler" />
                                </p>
                            </form>
                            <br clear="all" />
                        </div>
                    </div>
                    <div class="footer">
                        <p></p>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
